package com.link.base.base.projectmanage.controller;

import com.link.base.base.projectmanage.model.CarRegBusManagerInter;
import com.link.base.base.projectmanage.model.CarRegister;
import com.link.base.base.projectmanage.service.CarRegBusManagerInterService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.model.ReturnCodeConstants;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.BasicServiceException;
import com.link.core.basic.service.KeyGenerateService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 员工与车型登记中间表（业务经理）
 *
 * @author 刘启鑫
 * @date 2020-09-11 17:20:44
 */
@Controller
@RequestMapping("/link/carRegBusManagerInter")
public class CarRegBusManagerInterController extends BasicController<CarRegBusManagerInter> {


    private static final Logger logger = LogManager.getLogger(CarRegBusManagerInterController.class);


    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private CarRegBusManagerInterService carRegBusManagerInterService;

    @Override
    public BasicService<CarRegBusManagerInter> getBasicService() throws Exception {
        return carRegBusManagerInterService;
    }


    @RequestMapping(value = "/deleteByCarRegId")
    @ResponseBody
    public Map<String, Object> deleteByCarRegId(@JsonParam CarRegister entity, HttpSession session,
                                                 HttpServletRequest request, HttpServletResponse response) {
        logger.info("删除一条列表信息...");
        Map<String, Object> result = new HashMap<>(4);
        try {
            Long carRegId = entity.getId();
            if (!Objects.isNull(carRegId)) {
                CarRegBusManagerInter inter = new CarRegBusManagerInter();
                inter.setCarRegId(carRegId);
                beforDelete(inter, request);
                checkData(inter, request);
                carRegBusManagerInterService.deleteByCarRegId(inter);
            }



            result.put("success", true);
            result.put("code", ReturnCodeConstants.SUCCESS);
        } catch (BasicServiceException e) {
            logger.error("BasicController捕获异常: ", e);
            result.put("success", false);
            result.put("result", e.getMessage());
            result.put("detailMessage", e.getDetailMessage());
            result.put("code", e.getCode());
        } catch (Exception e) {
            logger.error("BasicController捕获异常: ", e);
            result.put("success", false);
            result.put("result", e.getMessage());
            result.put("code", ReturnCodeConstants.EXCEPTION);
        }
        return result;
    }


}
